<?php
/**
 * @authors	sachin,shine,jonia
 * @copyright   CMM Technologies
 * @date        15-11-2011
 * @file		Client.cls.php
 * @description manipulation of common functions related to clients are handled here.
 */
 class Client extends Base
 {

	 /**
     * Client id
     * @var integer
     */
	 private $id;

	/**
     * Client name
     * @var string
     */
	 private $clientName;

	/**
     * Client address
     * @var string
     */
	 private $address;

	/**
     * email 
     * @var string
     */
	 private $email;

	/**
     * Phone number
     * @var string
     */
	 private $phoneNumber;
	
	/**
     * status
     * @var string
     **/
	 private $status;

	 public function __construct($id)
	 {
		parent::init();

		$this->id=$id;

		$data=self::$db->getDBContentsBySql("select * from tms_clients where id='$id'");
			
		$this->clientName=$data[0]['client_name'];
		$this->address=$data[0]['address'];
		$this->email=$data[0]['email'];
		$this->phoneNumber=$data[0]['phone_number'];
		$this->status=$data[0]['status'];
	 }

	 /**
     * Function to get the client name
	 *return string client name 
	 */
	 public function getClientName()
	 {
		 return $this->clientName;
	 }
		

	/**
     * Function to get the client address
	 *return string client address
	 */
	  public function getAddress()
	 {
		 return $this->address;
	 }

	
	/**
     * Function to get the client email
	 *return string email  
	 */
	  public function getEmail()
	 {
		 return $this->email;
	 }


	/**
     * Function to get the client phone number
	 *return string client phone number
	 */
	  public function getPhoneNumber()
	 {
		 return $this->phoneNumber;
	 }

 
	/**
     * Function to get the status
	 *return string client status
	 */
	 public function getStatus()
	 {
		 return $this->status;
	 }
	

	 /**
     * Function to get all projects of a particular Client
	 * return array contains list of projects
	 */
	 public function getProjects()
	 {
		 $id=$this->id;
		 $cond = "clients_id=$id";
		 $result = self::$db->getDBFieldByCond("tms_projects","id",$cond);
		 return $result;
	 }

	/**
     * Function to get all clients id
	 *return array, client id
	 */
	 public static function getClients()
	 {
		parent::init();
		$result = self::$db->getDBFieldByCond("tms_clients","id","true");
		return $result;
	 }


	 public static function addClient($name,$address,$email,$phone,$status)
	 {	
		parent::init();
		$fields = "client_name,address,email,phone_number,status";
		$values = array($name,$address,$email,$phone,$status);
		$result = self::$db->dbInsert("tms_clients",$fields,$values);
		return $result;
  	 }

/**
	 * Function to get client name from  client id 
	 * @param int $id 
	 * @return client name 
	 */ 
	   public  static function  getClientNameFromId($id)
	 {
		parent::init();
		$result=self::$db->getCellContentByCondition("tms_clients","client_name","id='$id'");
		return $result;
	 }
	

	  public static function deleteClient($id)
	 {
		 parent::init();
		$qry="DELETE FROM tms_clients WHERE id='$id'";
		$result=self::$db->executeQuery($qry);
		return $result;

	 }
 



 }
?>
